package www.ym.com.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import www.ym.com.common.R;
import www.ym.com.common.RL;
import www.ym.com.entity.Consum;
import www.ym.com.service.CompanyService;
import www.ym.com.service.ConsumService;

import java.util.List;

@RestController
@RequestMapping("/consum")
public class ConsumController {

    @Autowired
    private ConsumService consumService;

    /**
     * 新增消费记录
     * @param consum
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody Consum consum){
        consumService.save(consum);
        return R.success("","新增成功");
    }

    /**
     * 修改消费记录
     * @param consum
     * @return
     */
    @PutMapping("/update")
    public R<String> update(@RequestBody Consum consum){
        consumService.updateById(consum);
        return R.success("","修改成功");
    }

    /**
     * 删除消费记录
     * @param id
     * @return
     */
    @DeleteMapping("del")
    public R<String> del(Long id){
        consumService.removeById(id);
        return R.success("","删除成功");
    }


    /**
     * 列表
     * @param jsonObject
     * @return
     */
    @PostMapping("list")
    public RL<Consum> list(@RequestBody  JSONObject jsonObject){
        Page<Consum> consumPage = consumService.consunPage(jsonObject);
        List<Consum> records = consumPage.getRecords();
        long pageSize = consumPage.getSize();
        long pageNUm = consumPage.getCurrent();
        long total = consumPage.getTotal();
        return RL.listSuccess(records,"",total,pageNUm,pageSize);
    }

}
